<!--
**********************************************************
* @Author: 张小平
* @Date:   2024-05-01
* @Email:  qqshuqian@163.com
* @Last modified: 最后修改日期
* @Description: 文件描述
**********************************************************
-->
<template>
  <basic-container>
    <div class="avue-crud">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="部门名称" prop="name"><el-input v-model="queryParams.name" placeholder="请输入部门名称" clearable size="small" @keyup.enter.native="getList" /></el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
          <el-button v-if="permissions.sys_org_save_post" icon="el-icon-plus" type="primary" @click="addOrUpdateHandle(false)">添加</el-button>
        </el-form-item>
      </el-form>


      <el-table border v-loading="loading" :data="deptList" row-key="id" default-expand-all :tree-props="{children: 'children'}">
        <el-table-column prop="name" label="部门名称" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="weight" label="排序" align="center"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>

<!--        <el-table-column prop="type" label="类型" width="80" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag type="success" v-if="scope.row.type == '10'">省教育局</el-tag>-->
<!--            <el-tag type="success" v-if="scope.row.type == '20'">市教育局</el-tag>-->
<!--            <el-tag type="success" v-if="scope.row.type == '30'">区教育局</el-tag>-->
<!--            <el-tag type="success" v-if="scope.row.type == '40'">学校</el-tag>-->
<!--            <el-tag type="success" v-if="scope.row.type == '50'">学习中心</el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->

<!--        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--          <template #="scope">-->

<!--            <el-button size="small" link type="primary"  icon="el-icon-plus" @click="addOrUpdateHandle(false, scope.row.id)"    >新增</el-button>-->
<!--            <el-button size="small" link type="primary"  icon="el-icon-edit" @click="addOrUpdateHandle(true, scope.row.id)"    >修改</el-button>-->
<!--            <el-button size="small" link type="primary"  icon="el-icon-delete" @click="handleDelete(scope.row)"    >删除</el-button>-->
<!--          </template>-->



<!--        </el-table-column>-->
      </el-table>

<!--      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getList"></table-form>-->
    </div>
  </basic-container>
</template>

<script>
import {fetchTree} from '@/framework-admin/api/admin/dept'
import {listCore,delCore} from "@/framework-core/api/core/api";
import TableForm from "./dept-form.vue";

export default {
  name: "Dept",
  components: {TableForm},
  data() {
    return {
      addOrUpdateVisible: false,
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        name: ""
      },
      //表格树数据
      deptList: []
    };
  },
  created() {
    this.getList();
  },
  computed: {
    ...mapState({
      permissions: (state) =>state.user.permission,
    })
  },
  methods: {
    getPermission:function(key, row, index) {
      return false;
      // if(index>=0 &&"code" === key){
      //   return !(vaildData(row.canDo && this.permissions[this.pageConfig.url.replace("/","_")+"_save_post"]));
      // }
      // return this.getCommPermission(key, row, index);
    },
    getList() {
      this.loading = true;
      fetchTree().then(response => {
        this.deptList = response.data.data.data;
        //this.page.total = response.data.data.total;
        this.loading = false;
      });
    },
    
    addOrUpdateHandle(isEdit, id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(isEdit, id);
      });

    },
    
    handleDelete(row) {
      this.$confirm('是否确认删除名称为"' + row.name + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return delCore('sys/org',row);
        })
        .then(() => {
          this.getList();
          this.$message.success("删除成功");
        });
    }
  }
};
</script>
